<template>
  <div>
    <a-modal :visible="visible" @before-open="open" :on-before-ok="handleOk" @cancel="handleCancel" :align-center="false" title-align="start" width="500px" :mask-closable="false">
      <template #title> 备注名 </template>
      <div>
        <a-form auto-label-width ref="formRef" size="medium" :model="form">
          <a-space direction="vertical" :size="24">
            <a-row>
              <a-col :span="24">
                <a-form-item field="remark" label="备注名" :rules="rules.remark">
                  <a-input v-model="form.remark" placeholder="请输入备注名"></a-input>
                </a-form-item>
              </a-col>
            </a-row>
          </a-space>
        </a-form>
      </div>
    </a-modal>
  </div>
</template>

<script lang="ts">
  import { defineComponent, ref, reactive, toRefs, computed } from 'vue'
  import { updateLocationRemarkBatch } from '@/api/warehouse'
  import { Message } from '@arco-design/web-vue'
  import { done } from 'nprogress'
  export default defineComponent({
    props: ['ids', 'remarkText'],
    setup(props: any, { emit }) {
      let visible = ref(false)
      const formRef = ref()
      const data = reactive({
        form: {} as any,
        rules: {
          remark: [{ required: true, message: '请输入备注名' }],
        },
      })

      const open = () => {
        // getUserList()
        console.log(props)

        if (props.remarkText) {
          data.form.remark = props.remarkText
        }
      }
      const handleOk = (done: any) => {
        formRef.value.validate(async (valid: any) => {
          if (!valid) {
            let params: any = data.form
            params.ids = props.ids
            try {
              const res: any = await updateLocationRemarkBatch(params)
              if (res.code == 'SUCCESS') {
                data.form = {}
                Message.success('修改成功')
                visible.value = false
                emit('save')
              }
              done(true)
            } catch (error) {
              done(true)
            }
          } else {
            done(true)
          }
        })
      }
      const handleCancel = () => {
        data.form = {}
        visible.value = false
      }
      return {
        ...(toRefs(data) as any),
        visible,
        formRef,
        open,
        handleOk,
        handleCancel,
      }
    },
  })
</script>

<style lang="less" scoped></style>
